package com.example.apkplugdemo;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import org.apkplug.Bundle.ThemeControl;
import org.apkplug.Bundle.installCallback;
import org.apkplug.app.FrameworkFactory;
import org.apkplug.app.FrameworkInstance;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;

import com.apkplug.service.ApkplugCloudAgent;
import com.apkplug.service.appServiceManager;

import android.app.Application;
import android.content.Context;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.WindowManager;

public class ProxyApplication extends Application {

	private FrameworkInstance frame=null;
	
	public FrameworkInstance getFrame() {
		return frame;
	}

	public void onCreate() {   
		
		
		 super.onCreate(); 
		 try
	        {
	        	//启动框架
				//文档见 http://www.apkplug.com/javadoc/Maindoc1.4.6/
				//org.apkplug.app 
				//     接口 FrameworkInstance
				frame=FrameworkFactory.getInstance().start(null,this);
				//FrameworkFactory.getInstance().init(this);
				System.out.println("ProxyApplication1");
				BundleContext context =frame.getSystemBundleContext();
				//安装assets文件夹下的插件 该类替代了MyProperty.AutoStart()方法 ,1.6.7以上建议使用新方式
				//启动云服务包括插件搜索 下载 更新功能
				ApkplugCloudAgent.init(context);
				InstallBundle ib=new InstallBundle();
				ib.installBundle(getApplicationContext(), context, 
						new installCallback(){
							@Override
							public void callback(int arg0, Bundle arg1) {
								if(arg0==installCallback.stutas5||arg0==installCallback.stutas7){
									Log.d("",String.format("插件安装 %s ： %d",arg1.getName(),arg0));
									return;
								}
								else{
									Log.d("","插件安装失败 ：%s"+arg1.getName());
								}
							}
				});
	        }
	        catch (Exception ex)
	        {
	            System.err.println("Could not create : " + ex);
	            ex.printStackTrace();
	            int nPid = android.os.Process.myPid();
				android.os.Process.killProcess(nPid);
	        }
	}
	
}
